package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
 * Created with IntelliJ IDEA.
 * User: carapka
 * Date: 19.10.12
 * Time: 1:08
 * To change this template use File | Settings | File Templates.
 */
public class LoginPage extends AnyPage {
    @FindBy(id = "loginform")
    public WebElement loginform;

    @FindBy(id = "username")
    public WebElement userNameField;

    @FindBy(name = "password")
    public WebElement passwordField;

    @FindBy(name = "submit")
    public WebElement loginButton;


    public boolean isOnloginPage() {
        return loginform.isDisplayed();
    }

    @Override
    public void tryToOpen() {
        MyPageFactory.getPage(driver, InternalPage.class).logout();
    }


    public InternalPage login(String username, String password) {

        userNameField.sendKeys(username);

        passwordField.sendKeys(password);

        loginButton.click();

        return MyPageFactory.getPage(driver, InternalPage.class);
    }







    public LoginPage loginErr(String username, String password) {

        userNameField.sendKeys(username);

        passwordField.sendKeys(password);
        loginButton.click();

        return MyPageFactory.getPage(driver, LoginPage.class);
    }
}
